home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / datecls.exe / DATEDEMO.CPP < prev    next >
Text File  |  1992-06-28  |  6KB  |  150 lines

  1. #include "datecls4.h"
  2.  
  3. ////////////////////////////////////////////////////////////
  4. //    main for testing purposes only...
  5. ////////////////////////////////////////////////////////////
  6.  
  7. void main()
  8. {
  9.     cout << " Date Class v4.0 Demo \n\n";
  10.  
  11.     // Various versions of the constructors
  12.     // and various output
  13.  
  14.     Date x(10,20,1962);
  15.     cout << x.formatDate(FULL) << "\n";
  16.  
  17.     // constuctor with a string, just printing the day of the week
  18.     Date y="8/8/1988";
  19.     cout << y.formatDate(DAY) << "\n";
  20.  
  21.     // constructor with a julian
  22.     Date z( 2450000L );
  23.     cout << z.formatDate(FULL) << '\n';
  24.  
  25.     // using date addition and subtraction
  26.     Date a = x + 10;
  27.     cout << a.formatDate(FULL) << '\n';
  28.     a = a - 25;
  29.     cout << a.formatDate(EUROPEAN) << '\n';
  30.  
  31.     //using subtraction of two date objects
  32.     Date a1 = "7/13/1991";
  33.     Date a2 = a1 + 14;
  34.     cout << (a1-a2) << "\n";
  35.     cout << (a2+=10) << "\n";
  36.  
  37.     a1++;
  38.     cout << "Tommorrow= " << a1.formatDate(FULL) << "\n";
  39.  
  40.     cout << "a1 (7-14-91) < 8-01-91 ? ==> " << ((a1 < "08/01/1991") ? "TRUE" : "FALSE") << "\n";
  41.     cout << "a1 (7-14-91) > 8-01-91 ? ==> " << ((a1 > "08/01/1991") ? "TRUE" : "FALSE") << "\n";
  42.     cout << "a1 (7-14-91)== 7-14-91 ? ==> " << ((a1==(Date)"07/14/1991") ? "TRUE" : "FALSE") << "\n";
  43.     Date a3 = a1;
  44.     cout << "a1 (7-14-91)== a3 (7-14-91) ? ==> " << ((a1==a3) ? "TRUE" : "FALSE") << "\n";
  45.     Date a4 = a1;
  46.     cout << "a1 (7-14-91)== a4 (7-15-91) ? ==> " << ((a1==++a4) ? "TRUE" : "FALSE") << "\n";
  47.  
  48.     Date a5 = "today";
  49.     cout << "Today is: " << a5 << "\n";
  50.     a4 = "Today";
  51.     cout << "Today (a4) is: " << a4 << "\n";
  52.  
  53.     cout << "Today + 4 is: " << (a4+=4) << "\n";
  54.     a4 = "TODAY";
  55.     cout << "Today - 4 is: " << (a4-=4) << "\n";
  56.  
  57.     cout << "=========== Leap Year Test ===========\n";
  58.     a1 = "1/15/1992";
  59.     cout << a1.formatDate(FULL) << "\t" << ((a1.isLeapYear()) ? "Leap" : "non-Leap");
  60.     cout << "\t" << "day of year:  " << a1.DOY() << "\n";
  61.  
  62.     a1 = "2/16/1993";
  63.     cout << a1.formatDate(FULL) << "\t" << ((a1.isLeapYear()) ? "Leap" : "non-Leap");
  64.     cout << "\t" << "day of year:  " << a1.DOY() << "\n";
  65.  
  66.     _dosdate_t b0 = {15,02,1991,1};
  67.     Date b1 = b0;
  68.     cout << "=========== eom test ==============\n";
  69.     cout << "b1.eom() (s/b 2/28/91) ==> " << b1.eom() << "\n";
  70.  
  71.     cout << "================== getDate test =====================\n";
  72.     _dosdate_t ds = a1.getDate();
  73.     cout << "a1.getDate()  (s/b 2/16/1993) ==> " << ds << "\n";
  74.  
  75.     cout << "================== string assignment test ====================\n";
  76.     char *date_string=a1;
  77.     cout << "a1 as a string (s/b 2/16/1993) ==> " << date_string << "\n";
  78.  
  79.     cout << "================== setFormat test ============================\n";
  80.     Date::setFormat(FULL);
  81.     cout << "a1 (s/b FULL format) ==> " << a1 << "\n";
  82.     Date::setFormat(EUROPEAN);
  83.     cout << "a1 (s/b EUROPEAN format) ==> " << a1 << "\n";
  84.  
  85.     cout << "================== setOption test ============================\n";
  86.     cout << "Date abbreviation ON\n";
  87.     Date::setOption(DATE_ABBR);
  88.     Date::setFormat(MONTH);
  89.     cout << "a1 (s/b MONTH format) ==> " << a1 << "\n";
  90.     Date::setFormat(DAY);
  91.     cout << "a1 (s/b DAY format) ==> " << a1 << "\n";
  92.     Date::setFormat(FULL);
  93.     cout << "a1 (s/b FULL format) ==> " << a1 << "\n";
  94.     Date::setFormat(EUROPEAN);
  95.     cout << "a1 (s/b EUROPEAN format) ==> " << a1 << "\n";
  96.     cout << "Century suppression ON\n";
  97.     Date::setOption(NO_CENTURY);
  98.     Date::setFormat(MDY);
  99.     cout << "a1 (s/b MDY format) ==> " << a1 << "\n";
  100.     cout << "Century suppression OFF\n";
  101.     Date::setOption(NO_CENTURY,OFF);
  102.     cout << "a1 (s/b MDY format) ==> " << a1 << "\n";
  103.     cout << "Century suppression ON\n";
  104.     Date::setOption(NO_CENTURY);
  105.     cout << "a1 (s/b MDY format) ==> " << a1 << "\n";
  106.     Date::setFormat(FULL);
  107.     cout << "a1 (s/b FULL format) ==> " << a1 << "\n";
  108.     Date::setOption(DATE_ABBR,OFF);
  109.  
  110.     cout << "\n=============== Version 4.0 Enhancement Test =================\n";
  111.     
  112.     Date v4("11/26/1966");
  113.     cout << "\n---------- Set Stuff -----------\n";
  114.     cout << "First, 'Set' to today..." << "\n";
  115.     cout << "Before 'Set' => " << v4 << "\n";
  116.     cout << "After  'Set' => " << v4.Set() << "\n\n";
  117.  
  118.     cout << "Set to 11/26/66 => " << v4.Set(11,26,1966) << "\n";
  119.     cout << "Current Julian  => " << v4.julDate() << "\n";
  120.     cout << "Set to Julian 2450000L => " << v4.Set(2450000L) << "\n";
  121.     cout << "See! => " << v4.julDate() << "\n";
  122.  
  123.     cout << "---------- Add Stuff -----------\n";
  124.     cout << "Start => " << v4 << "\n";
  125.     cout << "Add 4 Weeks => " << v4.AddWeeks(4) << "\n";
  126.     cout << "Sub 1 Month => " << v4.AddMonths(-1) << "\n";
  127.     cout << "Add 2 Years => " << v4.AddYears(2) << "\n";
  128.  
  129.     cout << "---------- Misc Stuff -----------\n";
  130.     cout << "The date aboves' day of the month is => " << v4.Day() << "\n";
  131.     cout << "There are " << v4.DaysInMonth() << " days in this month.\n";
  132.     cout << "The first day of this month lands on " << v4.FirstDOM() << "\n";
  133.     cout << "This day happens to be " << v4.CDOW() << "\n";
  134.     cout << "the " << v4.NDOW() << " day of the week," << "\n";
  135.     cout << "on the " << v4.WOY() << " week of the year," << "\n";
  136.     cout << "on the " << v4.WOM() << " week of the month, " << "\n";
  137.     cout << "(which is " << v4.CMonth() << ")\n";
  138.     cout << "the "<< v4.NMonth() << "nth month in the year.\n";
  139.     cout << "The year alone is " << v4.NYear4() << "\n";
  140.  
  141.     cout << "---------- First and Last Stuff -----------\n";
  142.     v4.Set();
  143.     cout << "The first date of this month is " << v4.BOM() << "\n";
  144.     cout << "The last date of this month is " << v4.EOM() << "\n";
  145.     cout << "The first date of this year is " << v4.BOY() << "\n";
  146.     cout << "The last date of this year is " << v4.EOY() << "\n";
  147.  
  148. }
  149.  
  150.